package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.ServiceEndDateAttrHandler;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.ServiceStartDateAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandlers;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.enums.ActionType;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import org.springframework.stereotype.Service;

/**
 * @author lyx
 * @version V1.0
 * @Description:
 * @date 2021/3/17
 * @Package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler
 */
@Service
@AttrHandlers({ @AttrHandler(ServiceStartDateAttrHandler.class), @AttrHandler(ServiceEndDateAttrHandler.class)
}) public class ServiceDateAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        /**
         * 截至时间要大于起始时间
         */
        // 服务起始时间
        String startDate = inst.getAttrValue("210003980");
        // 服务截止时间
        String endDate = inst.getAttrValue("210003981");
        if (KiteStringUtils.isNotBlank(startDate) && KiteStringUtils.isNotBlank(endDate) && inst.getActionType()
            .equals(ActionType.A)) {
            int startDateInt = Integer.parseInt(startDate.replace("-", ""));

            int endDateInt = Integer.parseInt(endDate.replace("-", ""));
            if (startDateInt > endDateInt) {
                ErrorConsts.BUSI_COMMON_ERROR.throwOut("服务截止时间需要大于服务起始时间，请重新输入！");
            }
        }

    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
